data "aws_ami" "amazonlinux" {
  most_recent = true

  filter {
    name   = "owner-alias"
    values = ["amazon"]
  }

  filter {
    name   = "name"
    values = ["amzn2-ami-hvm*"]
  }

  owners = ["amazon"]
}

resource "aws_instance" "instance" {
  ami                  = data.aws_ami.amazonlinux.id
  instance_type        = var.instance_type
  iam_instance_profile = var.iam_instance_profile
  network_interface {
    network_interface_id = var.network_interface_id
    device_index         = var.device_index
  }

  tags = {
    Name = var.name
  }
}
